<?php

namespace App\Http\Controllers;

use App\Library\Lock;
use App\Library\Requests\AfterSale\AfterSaleAuctionApply;
use App\Library\Requests\Base\BaseDeliveryRequest;
use App\Library\Requests\Base\BasePageRequest;
use App\Library\Requests\Base\SerialNumberRequest;
use App\Library\Service\AfterSaleService;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Http\JsonResponse;

class AfterSaleController extends BaseController
{
    /**
     * @param AfterSaleService $service
     */
    public function __construct(AfterSaleService $service)
    {
        $this->service = $service;
    }

    public function auctionApply(AfterSaleAuctionApply $request): JsonResponse
    {
        return $this->service->auctionApply($request);
    }

    /**
     * 售后详情
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function auctionDetail(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->auctionDetail($request);
    }

    public function afterSaleList(BasePageRequest $request): JsonResponse
    {
        return $this->service->afterSaleList($request);
    }
    public function refund(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->refund($request);
    }

    /**
     * 取消售后
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function auctionCancel(SerialNumberRequest $request): JsonResponse
    {
        return Lock::get($request->serialNumber . 'afterSale', function () use ($request) {
            return $this->service->auctionCancel($request);
        });
    }

    /**
     * 售后买家发货
     * @param BaseDeliveryRequest $request
     * @return JsonResponse
     *
     * @throws GuzzleException
     */
    public function userDelivery(BaseDeliveryRequest $request): JsonResponse
    {
        return $this->service->userDelivery($request);
    }

    /**
     *
     * @param SerialNumberRequest $request
     * @return JsonResponse
     *
     */
    public function logistics(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->logistics($request);
    }
}
